﻿using System.Collections.Generic;
using System.Linq;
using EzDesk.Core.Data;
using EzDesk.Core.Model;

namespace EzDesk.Core.ServiceImpl.Services
{
    public static class UserProfileModelEx
    {
        public static SimpleUser ToSimpleUser(this UserProfile userProfile)
        {
            return new SimpleUser()
                       {
                           Dept = userProfile.Dept,
                           Position = userProfile.Position,
                           Id = userProfile.Id,
                           Name = userProfile.Name,
                           UserName = userProfile.UserCode
                       };
        }
        public static List<SimpleUser> ToSimpleUsers(this List<UserProfile> userProfiles)
        {
            var simpleUsers = new List<SimpleUser>();
            return EzDeskDatabaseContainer.Go(
                container =>
                    {
                        
                        foreach (var userProfile in userProfiles)
                        {
                            if (userProfile != null)
                            {
                                userProfile.HeadUrl = string.Format("/core/headicon/{0}/{1}", userProfile.Id,
                                                                    userProfile.HeadImageId);
                            }
                            simpleUsers.Add(userProfile.ToSimpleUser());
                        }
                        return simpleUsers;
                    });
        }

    }
}